home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-15 | 2.6 KB | 95 lines | [TEXT/MMCC] |
- // ===========================================================================
- // CMyCustomListBox.cp ©1994 Jan Bruyndonckx All rights reserved.
- // v1.0 18/6/94
- //
- // A listbox subclass containing an icon and a p-string
- // ===========================================================================
-
- #include <string.h>
- #include "CMyCustomListBox.h"
-
- typedef struct {
-
- short iconID ;
- Str255 name ; // actually, we'll use only as much as needed…
-
- } MyCustomDataRec, *MyCustomDataRecPtr ;
-
- typedef struct {
-
- short iconID ;
- StringPtr name ;
-
- } MyCustomData ;
-
- MyCustomData sMyCustomData[] = {
-
- -4000, "\pdocument",
- -3999, "\pfolder",
- -3998, "\pfloppy",
- -3996, "\papplication",
- -3995, "\phard disk",
- -3993, "\ptrash",
- -3985, "\pstationary",
- -3972, "\pserver",
- -3970, "\psuitcase"
- } ;
-
- //----------------------------------------------------------------------------
-
- CMyCustomListBox* CMyCustomListBox::CreateFromStream (LStream *inStream)
- {
- return (new CMyCustomListBox(inStream));
- }
-
- //----------------------------------------------------------------------------
-
- CMyCustomListBox::CMyCustomListBox (LStream *inStream) : CCustomListBox (inStream)
- { const short numCells = sizeof (sMyCustomData) / sizeof (MyCustomData) ;
- Cell cell = { 0, 0 } ;
- short &i = cell.v ;
-
- ::LAddRow (numCells, 0, mMacListH) ;
-
- for (cell.v = 0 ; cell.v < numCells ; cell.v++)
- { MyCustomDataRec cellData ;
- cellData.iconID = sMyCustomData[i].iconID ;
- ::memcpy (cellData.name, sMyCustomData[i].name, *sMyCustomData[i].name+1) ;
- ::LSetCell (&cellData, sizeof (short) + *cellData.name + 1, cell, mMacListH) ;
- }
- }
-
- //----------------------------------------------------------------------------
-
- void CMyCustomListBox::DrawElementSelf (const Rect *lRect,
- const void *lElement,
- const short lDataLen)
- { Rect sicnBox ;
- MyCustomDataRecPtr cellData = (MyCustomDataRecPtr) lElement ;
-
- sicnBox.left = lRect->left + 3 ;
- sicnBox.top = lRect->top - 1 ;
- sicnBox.right = sicnBox.left + 16 ;
- sicnBox.bottom = sicnBox.top + 16 ;
-
- Handle h = ::GetResource ('SICN', cellData->iconID) ;
- if (h != NULL)
- { char saveState = ::HGetState (h) ;
- ::HLock(h) ;
-
- BitMap srcBits = { *h, 2, { 0, 0, 16, 16 }}; // baseAddr, rowBytes, bounds
- GrafPtr port ;
-
- ::GetPort (&port) ;
- ::CopyBits (&srcBits, &(*port).portBits,
- &srcBits.bounds, &sicnBox,
- srcCopy, NULL) ;
-
- ::HSetState (h, saveState) ;
- }
- ::MoveTo (lRect->left + 24, lRect->top + 10) ;
- ::DrawString (cellData->name) ;
- }
-
- //----------------------------------------------------------------------------
-